﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;

namespace Kiosk.OutlookAddIn
{
    public partial class ThisAddIn
    {
        private Office.CommandBarButton btnSendToKiosk;
        private Outlook.AppointmentItem calendarEvent;

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            this.Application.ItemContextMenuDisplay += new Outlook.ApplicationEvents_11_ItemContextMenuDisplayEventHandler(Application_ItemContextMenuDisplay);
        }

        void Application_ItemContextMenuDisplay(Microsoft.Office.Core.CommandBar CommandBar, Microsoft.Office.Interop.Outlook.Selection Selection)
        {
            if (Selection.Count == 1 && Selection[1] is Outlook.AppointmentItem)
            {
                calendarEvent = (Outlook.AppointmentItem)Selection[1];
                btnSendToKiosk = CommandBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, missing) as Office.CommandBarButton;

                btnSendToKiosk.Caption = "Send to Kiosk...";

                btnSendToKiosk.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btn_Click);

            }
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        void btn_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)
        {
            if (calendarEvent != null)
            {
                calendarEvent.MessageClass = "IPM.Magenic.KioskNotification";
                calendarEvent.FormDescription.UseWordMail = false;
                calendarEvent.Display(false);
            }
        }


        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }
}
